<template>
  <div class="banner" :style="{
    backgroundColor: config.pageConfig.color,
  }">
    <div :style="{
      marginTop: config.pageConfig.marginTop + 'px',
      marginBottom: config.pageConfig.marginBottom + 'px',
      marginLeft: config.pageConfig.margin + 'px',
      marginRight: config.pageConfig.margin + 'px',
    }" :class="`goods-${config.pageConfig.custom}`">
      <div v-for="(item, idx) in contentList" :key="idx" class="content-list" :style="
        config.pageConfig.custom == '3' || config.pageConfig.custom == '4'
          ? {
            width: `calc(50% - ${config.pageConfig.distance}px)`,
            margin: `${config.pageConfig.distance / 2}px`,
          }
          : {
            marginBottom: config.pageConfig.distance + 'px',
          }
      ">
        <div :style="{
          borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
          borderTopRightRadius: config.pageConfig.radiusTop + 'px',
          borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
          borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
          borderColor: config.pageConfig.borderColor,
          backgroundColor: config.pageConfig.goodsColor,
        }">
          <div class="goods-label" :class="
            config.pageConfig.dotStyle == 1
              ? 'goods-icon1'
              : config.pageConfig.dotStyle == 2
                ? 'goods-icon2'
                : 'goods-icon3'
          " v-if="config.pageConfig.dotSetting == 2">
            {{ config.pageConfig.dotName }}
          </div>
          <div class="goods-label" v-if="config.pageConfig.dotSetting == 3">
            <img :src="config.pageConfig.dotUrl" v-if="config.pageConfig.dotUrl" alt="" />
            <img v-else src="../../../../../../assets/app/bar/default_banner.png" alt="" />
          </div>
          <img :style="{
            borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
            borderTopRightRadius: config.pageConfig.radiusTop + 'px',
            borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
            borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
          }" v-if="item.imgUrl" :src="item.imgUrl" class="banner-img" alt="" />

          <img :style="{
            borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
            borderTopRightRadius: config.pageConfig.radiusTop + 'px',
            borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
            borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
          }" v-else src="../../../../../../assets/app/bar/default_banner.png" class="banner-img" alt="" />
          <div class="goods-detail">
            <h4 v-if="config.pageConfig.titleShow" :style="{
              color: config.pageConfig.titlecolor,
            }">
              {{ item.title }}
            </h4>
            <p class="subtitle" v-if="
              config.pageConfig.subtitleShow &&
              (config.pageConfig.custom == '1' ||
                config.pageConfig.custom == '2' ||
                config.pageConfig.custom == '3')
            " :style="{
  color: config.pageConfig.subtitlecolor,
}">
              {{ item.subtitle }}
            </p>
            <p class="salenum" v-if="
              config.pageConfig.salenumShow &&
              (config.pageConfig.custom == '1' ||
                config.pageConfig.custom == '2' ||
                config.pageConfig.custom == '3')
            " :style="{
  color: config.pageConfig.salenum,
}">
              已售{{ item.salenum }}
            </p>
            <div>
              <p v-if="config.pageConfig.priceShow" :style="{
                color: config.pageConfig.price,
              }">
                ￥{{ item.price }}.00<span v-if="
                  config.pageConfig.delpriceShow &&
                  (config.pageConfig.custom == '1' ||
                    config.pageConfig.custom == '2' ||
                    config.pageConfig.custom == '3')
                " :style="{
  color: config.pageConfig.delprice,
}">￥{{ item.delPrice }}.00</span>
              </p>
              <p v-if="config.pageConfig.custom != '4'" class="purchase">
                <span v-if="
                  config.pageConfig.custom == '1' ||
                  config.pageConfig.custom == '2' ||
                  config.pageConfig.custom == '3'
                ">购买</span>
                <el-icon v-else>
                  <CirclePlusFilled />
                </el-icon>
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: "Image",
};
</script>
<script lang="ts" setup>
import { reactive, onMounted } from "vue";
const config = defineProps({
  pageConfig: {
    type: Object,
    default: {
      custom: "3",
      style: "1",
      color: "transparent",
      goodsColor: "#fff",
      titlecolor: "#37383A",
      titleShow: true,
      subtitlecolor: "#999ca7",
      subtitleShow: true,
      priceShow: true,
      price: "#fd463e",

      delpriceShow: true,
      delprice: "#999CA7",
      salenumShow: true,
      salenum: "#999CA7",
      carUrl: "",
      borderWidth: 1,
      borderColor: "#ededed",
      dotSetting: "1",
      dotStyle: "1",
      dotName: "热卖",
      dotUrl: "",
      distance: 12,
      marginTop: 12,
      marginBottom: 12,
      marginImg: 12,
      margin: 12,
      radiusTop: 4,
      radiusBottom: 4,
      goodsType: 1,
      classifyId: "",
      groupId: "",
      sortType: 1,
      imgList: [],
    },
  },
});
const contentList = ref([] as Array<any>);
const getContentList = () => {
  //contentList是由goodType classifyId sortType共同决定的
  contentList.value.push(
    {
      id: "",
      title: "杯子男家用马克杯瓷杯陶瓷女创意个性北欧办公室喝水杯早餐杯",
      subtitle: "杯子男家用马克杯瓷杯陶瓷女创意个性北欧办公室喝水杯早餐杯",
      price: "99",
      delPrice: "129",
      salenum: "0",
      imgUrl: "",
      name: "",
      url: "",
    },
    {
      id: "",
      title: "杯子男家用马克杯瓷杯陶瓷女创意个性北欧办公室喝水杯早餐杯",
      subtitle: "杯子男家用马克杯瓷杯陶瓷女创意个性北欧办公室喝水杯早餐杯",
      price: "99",
      delPrice: "129",
      salenum: "",
      imgUrl: "",
      name: "",
      url: "",
    },
    {
      id: "",
      title: "杯子男家",
      subtitle: "杯子男家用马克杯瓷杯陶瓷女创意个性北欧办公室喝水杯早餐杯",
      price: "99",
      delPrice: "129",
      salenum: "",
      imgUrl: "",
      name: "",
      url: "",
    }
  );
};

let emits = defineEmits<{ (e: "close", flag: boolean): void }>();
onMounted(() => {
  getContentList();
});
</script>
<style lang="scss" scoped>
.banner {
  width: 100%;
  overflow: hidden;

  .content-list {
    >div {
      position: relative;

      .goods-label {
        position: absolute;
        z-index: 10;
        color: #fff;
        font-size: 22px;
        transform: scale(0.5);
        transform-origin: top left;

        &.goods-icon1 {
          width: 60px;
          height: 60px;
          background: url(@/assets/app/other/goods/hotbg-1.png);
          background-size: 60px;
          line-height: 44px;
          text-align: center;
        }

        &.goods-icon2 {
          width: 52px;
          height: 56px;
          background: url(@/assets/app/other/goods/hotbg-2.png);
          background-size: 52px 56px;
          line-height: 44px;
          text-align: center;
        }

        &.goods-icon3 {
          width: 64px;
          height: 44px;
          background: url(@/assets/app/other/goods/hotbg-3.png);
          background-size: 64px 44px;
          line-height: 44px;
          text-align: center;
        }

        img {
          width: 76px;
          height: 76px;
        }
      }
    }
  }
}

.goods-detail {
  position: relative;
  overflow: hidden;
  padding: 8px 12px;
  box-sizing: border-box;

  h4 {
    font-size: 14px;
    line-height: 18px;
    max-height: 36px;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .subtitle {
    font-size: 12px;
    height: 16px;
    line-height: 16px;
    width: 100%;
    color: #999ca7;
    margin-bottom: 4px;
    overflow: hidden;
    word-break: break-all;
    text-overflow: ellipsis;
  }

  .salenum {
    font-size: 13px;
    line-height: 18px;
    margin-bottom: 6px;
  }

  div {
    display: flex;
    align-items: center;
    justify-content: space-between;

    p {
      font-size: 14px;
      overflow: hidden;
      text-overflow: ellipsis;
      font-weight: 700;

      span {
        font-size: 12px;
        height: 13px;
        line-height: 13px;
        color: #999ca7;
        text-decoration: line-through;
      }
    }
  }
}

.goods-1 {
  >div {
    &:first-of-type {
      padding-top: 0;
    }

    div {
      position: relative;
      overflow: hidden;
      box-sizing: border-box;

      img {
        width: 100%;
      }

      .goods-detail {
        padding: 10px 12px 12px;

        h4 {
          max-height: 44px;
          font-size: 16px;
          line-height: 22px;
          font-weight: 700;
          margin-bottom: 6px;
        }

        .subtitle {
          font-size: 14px;
          height: 20px;
          line-height: 20rpx;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }

        .purchase {
          z-index: 2;
          padding: 4px 8px;
          border: 1px solid #f55;
          background: #f55;
          color: #fff;
          font-size: 12px;
          font-weight: 700;
          display: flex;
          align-items: center;

          span {
            color: #fff;
            line-height: 1;
            text-decoration: initial;
          }
        }

        .salenum {
          font-size: 13px;
          line-height: 18px;
          margin-bottom: 6px;
        }

        div {
          p {
            font-size: 18px;
            line-height: 18px;

            span {
              font-size: 14px;
              line-height: 24px;
              align-self: flex-end;
            }
          }
        }
      }
    }
  }
}

.goods-2 {
  >div {
    display: block;
    overflow: hidden;

    div {
      display: flex;

      img {
        width: 130px;
        height: 130px;
      }

      .goods-detail {
        display: block;

        .purchase {
          z-index: 2;
          padding: 4px 8px;
          border: 1px solid #f55;
          background: #f55;
          color: #fff;
          font-size: 12px;
          font-weight: 700;
          display: flex;
          align-items: center;

          span {
            color: #fff;
            line-height: 1;
            text-decoration: initial;
          }
        }
      }
    }
  }
}

.goods-3 {
  display: flex;
  flex-wrap: wrap;

  >div {
    img {
      width: 100%;
    }

    .goods-detail {
      h4 {
        height: 40px;
        max-height: 40px;
        font-size: 15px;
        line-height: 20px;
        font-weight: 700;
        margin-bottom: 6px;
      }

      >div {
        p {
          span {
            display: block;
          }
        }
      }

      .purchase {
        z-index: 2;
        padding: 4px 8px;
        border: 1px solid #f55;
        background: #f55;
        color: #fff;
        font-size: 12px;
        font-weight: 700;
        display: flex;
        align-items: center;

        span {
          color: #fff;
          line-height: 1;
          text-decoration: initial;
        }
      }
    }
  }
}

.goods-4 {
  >div {
    float: left;

    img {
      width: 100%;
    }

    .goods-detail {
      h4 {
        height: 40px;
        max-height: 40px;
        font-size: 15px;
        line-height: 20px;
        font-weight: 400;
        margin-bottom: 6px;
      }
    }
  }
}
</style>
